'use strict';

/**
 * Config for the router
 */
app.config(['$authProvider', '$stateProvider', '$httpProvider', '$urlRouterProvider', '$controllerProvider', '$compileProvider', '$filterProvider', '$provide', '$ocLazyLoadProvider', 'JS_REQUIRES',
    function($authProvider, $stateProvider, $httpProvider, $urlRouterProvider, $controllerProvider, $compileProvider, $filterProvider, $provide, $ocLazyLoadProvider, jsRequires) {

        //$authProvider,
        app.controller = $controllerProvider.register;
        app.directive = $compileProvider.directive;
        app.filter = $filterProvider.register;
        app.factory = $provide.factory;
        app.service = $provide.service;
        app.constant = $provide.constant;
        app.value = $provide.value;

        $authProvider.configure({
            // apiUrl: 'http://23.1.1.173:9002/services',
            apiUrl: 'http://192.168.3.233:9002/services',
            tokenValidationPath: '/auth/validate_token',
            signOutUrl: '/auth/logout',
            emailSignInPath: '/auth/login',
            //   confirmationSuccessUrl:  window.location.href,
            //   passwordResetPath:       '/auth/password',
            //   passwordUpdatePath:      '/auth/password',
            //   passwordResetSuccessUrl: window.location.href,
            storage: 'cookies',
            forceValidateToken: true,
            validateOnPageLoad: true,
            // authProviderPaths: {
            //  local:   '/auth/login'
            // },
            tokenFormat: {
                "access-token": "{{ token }}",
                //client: "{{ clientId }}",
                expiry: "{{ expiry }}",
                uid: "{{ uid }}"
            },
            cookieOps: {
                //      path: "/",
                expires: 9999,
                expirationUnit: 'seconds',
                //     secure: false,
                //     domain: 'dashitech.com'
            },
            parseExpiry: function(headers) {
                // convert from UTC ruby (seconds) to UTC js (milliseconds)
                return (parseInt(headers['expiry'])) || null;
            },
            handleLoginResponse: function(response, authscope) {
                var authData = {

                };
                console.log(authscope);
                if (response.sessionId == null) {
                    authData.error = 400;
                    //login failed
                    //$rootScope.$broadcast('auth:login-error', response);
                } else {
                    response.user.menu = response.menu;
                    authData = {
                        auth_token: response.sessionId,
                        client_id: 1,
                        uid: response.user.id,
                        expiry: response.seconds
                    };
                    angular.extend(authData, response.user);
                    return authData;
                }
                return authData;
            },
            handleLoginheaders: function(response, authscope) {
                var authData = {

                };
                if (response.sessionId == null) {
                    authData.error = 400;
                } else {
                    authData = {
                        "access-token": response.sessionId,
                        expiry: response.seconds,
                        uid: response.user.id
                    };
                }
                return authData;
            },
            handleAccountUpdateResponse: function(response) {
                return response;
            },
            handleTokenValidationResponse: function(response) {
                var authData = {

                };
                if (response.state == 200) {
                    response.user.menu = response.menu;
                    authData = {
                        auth_token: response.sessionId,
                        client_id: 1,
                        uid: response.user.id,
                        expiry: response.seconds
                    }
                    angular.extend(authData, response.user);
                } else {
                    authData.error = 500;
                }
                return authData;
            }
        });
        // LAZY MODULES

        $ocLazyLoadProvider.config({
            debug: false,
            events: true,
            modules: jsRequires.modules
        });
        // APPLICATION ROUTES
        // -----------------------------------
        // For any unmatched url, redirect to /app/dashboard
        $urlRouterProvider.otherwise("/app/dashboard");
        //
        // Set up the states
        $stateProvider.state('app', {
                url: "/app",
                templateUrl: "assets/views/app.html",
                resolve: loadSequence('modernizr', 'moment', 'angularMoment', 'uiSwitch', 'perfect-scrollbar-plugin', 'toaster', 'ngAside', 'vAccordion', 'sweet-alert', 'chartjs', 'tc.chartjs', 'oitozero.ngSweetAlert', 'chatCtrl'),
                abstract: true
            }).state('app.dashboard', {
                url: "/dashboard",
                templateUrl: "assets/views/dashboard.html",
                resolve: loadSequence('jquery-sparkline', 'moment', 'mwl.calendar', 'ng-nestable', 'ngTable', 'dashboardCtrl'),
                title: 'dashboard.MAIN',
                ncyBreadcrumb: {
                    label: 'Dashboard'
                }
            })
            .state('app.incident', {
                url: '/incident',
                template: '<div ui-view class="fade-in-up"></div>',
                title: 'incident',
                pdKey: 'bpm_incident',
                ncyBreadcrumb: {
                    label: 'Incident'
                }
            }).state('app.incident.list', {
                url: '/list',
                templateUrl: "assets/views/incident/list.html",
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'incidentCtrl'),
                title: 'incident.LIST',
                pdKey: 'bpm_incident',
                icon: 'ti-list',
                ncyBreadcrumb: {
                    label: 'incident list'
                }
            }).state('app.incident.editor', {
                url: '/editor/{taskId}/{processInstanceId}',
                templateUrl: "assets/views/customform/index.html",
                resolve: loadSequence('jquery-nestable-plugin', 'spin', 'ladda', 'angular-ladda', 'ng-nestable', 'ngTable', 'ui.select', 'angularBootstrapNavTree', 'monospaced.elastic', 'touchspin-plugin', 'ckeditor-plugin', 'ckeditor', 'jquery-sparkline', 'ui.mask', 'api-check', 'formly', 'angularFormly', 'angularFileUpload', 'multi.select.tree', 'd3', 'customformCtrl'),
                title: 'incident.NEW',
                pdKey: 'bpm_incident',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'new incident'
                }
            }).state('app.incident.watch', {
                url: '/watch/{model}',
                templateUrl: "assets/views/customform/index.html",
                resolve: loadSequence('jquery-sparkline', 'ui.mask', 'api-check', 'formly', 'angularFormly', 'angularFileUpload', 'multi.select.tree', 'customformCtrl'),
                title: 'incident.NEW',
                pdKey: 'bpm_incident',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'new incident'
                }
            }).state('app.incident.look', {
                url: '/look/{taskId}/{processInstanceId}',
                templateUrl: "assets/views/customform/indexlook.html",
                resolve: loadSequence('jquery-sparkline', 'ui.mask', 'api-check', 'formly', 'angularFormly', 'angularFileUpload', 'multi.select.tree', 'customformDetailCtrl'),
                title: 'incident.NEW',
                pdKey: 'bpm_incident',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'new incident'
                }
            })

        .state('app.watch', {
                url: '/watch',
                template: '<div ui-view class="fade-in-up"></div>',
                title: 'watch',
                pdKey: 'bpm_watch',
                ncyBreadcrumb: {
                    label: 'watch'
                }
            }).state('app.watch.list', {
                url: '/list',
                templateUrl: "assets/views/watch/watch.html",
                resolve: loadSequence('jquery-sparkline', 'ui.grid', 'watchCtrl'),
                title: 'watch.LIST',
                pdKey: 'bpm_watch',
                icon: 'ti-list',
                ncyBreadcrumb: {
                    label: 'watch list'
                }
            })
            .state('app.problem', {
                url: '/problem',
                template: '<div ui-view class="fade-in-up"></div>',
                title: 'problem',
                pdKey: 'bpm_problem',
                ncyBreadcrumb: {
                    label: 'Problem'
                }
            }).state('app.problem.list', {
                url: '/list',
                templateUrl: "assets/views/problem/list.html",
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'problemCtrl'),
                title: 'problem.LIST',
                pdKey: 'bpm_problem',
                icon: 'ti-list',
                ncyBreadcrumb: {
                    label: 'problem list'
                }
            }).state('app.problem.editor', {
                url: '/editor/{taskId}/{processInstanceId}',
                templateUrl: "assets/views/customform/index.html",
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'api-check', 'formly', 'angularFormly', 'angularFileUpload', 'multi.select.tree', 'angularBootstrapNavTree', 'd3', 'customformCtrl'),
                title: 'problem.NEW',
                pdKey: 'bpm_problem',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'new problem'
                }
            }).state('app.problem.incident', {
                url: '/incident/{model}',
                templateUrl: "assets/views/customform/index.html",
                resolve: loadSequence('jquery-sparkline', 'api-check', 'formly', 'angularFormly', 'angularFileUpload', 'multi.select.tree', 'customformCtrl'),
                title: 'problem.NEW',
                pdKey: 'bpm_problem',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'new problem'
                }
            }).state('app.change.problem', {
                url: '/change/{model}',
                templateUrl: "assets/views/customform/index.html",
                resolve: loadSequence('jquery-sparkline', 'api-check', 'formly', 'angularFormly', 'angularFileUpload', 'multi.select.tree', 'customformCtrl'),
                title: 'change.NEW',
                pdKey: 'bpm_change',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'new change'
                }
            })
            .state('app.change', {
                url: '/change',
                template: '<div ui-view class="fade-in-up"></div>',
                title: 'change',
                pdKey: 'bpm_change',
                ncyBreadcrumb: {
                    label: 'Change'
                }
            }).state('app.change.list', {
                url: '/list',
                templateUrl: "assets/views/change/list.html",
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'changeCtrl'),
                title: 'change.LIST',
                pdKey: 'bpm_change',
                icon: 'ti-list',
                ncyBreadcrumb: {
                    label: 'rfc list'
                } //incident
            }).state('app.change.editor', {
                url: '/editor/{taskId}/{processInstanceId}',
                templateUrl: "assets/views/customform/index.html",
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'api-check', 'formly', 'angularFormly', 'angularFileUpload', 'multi.select.tree', 'angularBootstrapNavTree', 'd3', 'customformCtrl'),
                title: 'change.NEW',
                pdKey: 'bpm_change',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'new rfc'
                }
            }).state('app.change.incident', {
                url: '/incident/{model}',
                templateUrl: "assets/views/customform/index.html",
                resolve: loadSequence('jquery-sparkline', 'api-check', 'formly', 'angularFormly', 'angularFileUpload', 'multi.select.tree', 'customformCtrl'),
                title: 'change.NEW',
                pdKey: 'bpm_change',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'new rfc'
                }
            })
            .state('app.change.release', {
                url: '/release/{model}',
                templateUrl: "assets/views/customform/index.html",
                resolve: loadSequence('jquery-sparkline', 'api-check', 'formly', 'angularFormly', 'angularFileUpload', 'multi.select.tree', 'customformCtrl'),
                title: 'change.NEW',
                pdKey: 'bpm_release',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'new rfc'
                }
            })
            .state('app.release', {
                url: '/release',
                template: '<div ui-view class="fade-in-up"></div>',
                title: 'release',
                pdKey: 'bpm_release',
                ncyBreadcrumb: {
                    label: 'release'
                }
            }).state('app.release.list', {
                url: '/list',
                templateUrl: "assets/views/release/list.html",
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'releaseCtrl'),
                title: 'release.LIST',
                pdKey: 'bpm_release',
                icon: 'ti-list',
                ncyBreadcrumb: {
                    label: 'release list'
                }
            }).state('app.release.editor', {
                url: '/editor/{taskId}/{processInstanceId}',
                templateUrl: "assets/views/customform/index.html",
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'api-check', 'formly', 'angularFormly', 'angularFileUpload', 'multi.select.tree', 'angularBootstrapNavTree', 'd3', 'customformCtrl'),
                title: 'release.NEW',
                pdKey: 'bpm_release',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'new release'
                }
            })
            .state('app.process', {
                url: '/process',
                template: '<div ui-view class="fade-in-up"></div>',
                title: 'Process',
                ncyBreadcrumb: {
                    label: 'Process'
                }
            }).state('app.process.list', {
                url: '/list',
                templateUrl: "assets/views/process/list.html",
                title: 'process.LIST',
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'processCtrl'),
                icon: 'ti-list',
                ncyBreadcrumb: {
                    label: 'Process list'
                }
            }).state('app.process.modeler', {
                url: '/modeler/{modelId}',
                templateUrl: "assets/views/process/modeler.html",
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'bpmn-js-properties', 'processCtrl'),
                title: 'process.MODELER',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'modeler'
                }
            })

        .state('app.cmdb', {
                url: '/cmdb',
                template: '<div ui-view class="fade-in-up"></div>',
                title: 'CMDB',
                ncyBreadcrumb: {
                    label: 'CMDB'
                }
            }).state('app.cmdb.plist', {
                url: '/plist',
                templateUrl: "assets/views/cmdb/plist.html",
                title: 'configuremanagerdb.PLIST',
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'cmdbCtrl'),
                pdKey: 'bpm_configure',
                icon: 'ti-list',
                ncyBreadcrumb: {
                    label: 'cmdbList'
                }
            }).state('app.cmdb.modeler', {
                url: '/editor/{taskId}/{processInstanceId}',
                templateUrl: "assets/views/customform/index.html",
                title: 'configuremanagerdb.MODELER',
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'api-check', 'formly', 'angularFormly', 'angularFileUpload', 'multi.select.tree', 'angularBootstrapNavTree', 'd3', 'customformCtrl'),
                pdKey: 'bpm_configure',
                icon: 'ti-list',
                ncyBreadcrumb: {
                    label: 'modeler'
                }
            })
            .state('app.cmdb.list', {
                url: '/list',
                templateUrl: "assets/views/cmdb/list.html",
                title: 'configuremanagerdb.LIST',
                resolve: loadSequence('spin', 'ladda', 'angular-ladda', 'jquery-sparkline', 'api-check', 'formly', 'angularFormly', 'angularFileUpload', 'multi.select.tree', 'angularBootstrapNavTree', 'ui.grid', 'customformCtrl', 'cmdbListCtrl'),
                icon: 'ti-list',
                ncyBreadcrumb: {
                    label: 'cmdbList'
                }
            }).state('app.cmdb.viewer', {
                url: '/view/{modelId}',
                templateUrl: "assets/views/cmdb/view.html",
                resolve: loadSequence('jquery-sparkline', 'ui.select', 'angularBootstrapNavTree', 'multi.select.tree', 'd3', 'cmdbViewCtrl'),
                title: 'configuremanagerdb.VIEW',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'cmdb viewer'
                }
            }).state('app.cmdb.change', {
                url: '/change/{model}',
                templateUrl: "assets/views/customform/index.html",
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'angularBootstrapNavTree', 'moment', 'angularFileUpload', 'ui.select', 'customformCtrl'),
                title: 'configuremanagerdb.MODELER',
                pdKey: 'bpm_configure',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'new rfc'
                }
            }).state('app.cmdb.log', {
                url: '/log',
                templateUrl: "assets/views/cmdb/log.html",
                title: 'configuremanagerdb.log',
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'angularBootstrapNavTree', 'moment', 'ui.select', 'logCtrl'),
                icon: 'ti-list',
                ncyBreadcrumb: {
                    label: 'cmdbList'
                }
            })
            .state('app.knowledge', {
                url: '/knowledge',
                template: '<div ui-view class="fade-in-up"></div>',
                title: 'knowledge',
                ncyBreadcrumb: {
                    label: 'knowledge'
                }
            }).state('app.knowledge.manager', {
                url: '/manager',
                templateUrl: "assets/views/knowledge/manager.html",
                resolve: loadSequence('jquery-nestable-plugin', 'ng-nestable', 'ui.select', 'monospaced.elastic', 'touchspin-plugin', 'angularBootstrapNavTree', 'ckeditor-plugin', 'ckeditor', 'angularFileUpload', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'knowledgeCtrl'),
                title: 'knowledgebase.VIEW',
                icon: 'ti-list',
                ncyBreadcrumb: {
                    label: 'knowledge list'
                }
            }).state('app.knowledge.forum', {
                url: '/forum',
                templateUrl: "assets/views/knowledge/forum.html",
                resolve: loadSequence('jquery-sparkline', 'jquery-nestable-plugin', 'ng-nestable', 'moment', 'ckeditor-plugin', 'ckeditor', 'knowledgeCtrl'),
                title: 'knowledgebase.LIST',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'knowledge forum'
                }
            })
            .state('app.scheduling', {
                url: '/scheduling',
                template: '<div ui-view class="fade-in-up"></div>',
                title: 'scheduling',
                pdKey: 'bpm_scheduling',
                ncyBreadcrumb: {
                    label: 'knowledge'
                }
            }).state('app.scheduling.myscheduling', {
                url: '/myscheduling',
                templateUrl: "assets/views/scheduling/mine.html",
                resolve: loadSequence('moment', 'mwl.calendar', 'ui.select', 'calendarCtrl', 'schedulingCtrl'),
                title: 'scheduling.MINE',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'scheduling'
                }
            }).state('app.scheduling.schedulecalendar', {
                url: '/schedule',
                templateUrl: "assets/views/scheduling/calendar.html",
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'moment', 'mwl.calendar', 'ui.select', 'calendarCtrl', 'angularFileUpload', 'schedulingCtrl'),
                title: 'scheduling.CALENDAR',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'scheduling'
                }
            }).state('app.scheduling.list', {
                url: '/list',
                templateUrl: "assets/views/scheduling/list.html",
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'angularFileUpload', 'schedulingCtrl'),
                title: 'scheduling.LIST',
                pdKey: 'bpm_schedule',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'scheduling'
                }
            }).state('app.scheduling.editor', {
                url: '/editor/{taskId}/{processInstanceId}',
                templateUrl: "assets/views/customform/index.html",
                title: 'scheduling.MODELER',
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'api-check', 'formly', 'angularFormly', 'angularFileUpload', 'multi.select.tree', 'schedulingCtrl', 'customformCtrl'),
                pdKey: 'bpm_schedule',
                icon: 'ti-list',
                ncyBreadcrumb: {
                    label: 'modeler'
                }
            }).state('app.scheduling.shift', {
                url: '/shift',
                templateUrl: "assets/views/scheduling/shift.html",
                resolve: loadSequence('jquery-sparkline', 'schedulingCtrl'),
                title: 'scheduling.SHIFT',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'scheduling shift'
                }
            }).state('app.scheduling.shiftrecord', {
                url: '/shiftrecord',
                templateUrl: "assets/views/scheduling/shiftrecord.html",
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'schedulingCtrl'),
                title: 'scheduling.SHIFTRECORD',
                icon: 'fa-tint',
                ncyBreadcrumb: {
                    label: 'scheduling record'
                }
            })
            .state('app.report', {
                url: '/report',
                template: '<div ui-view class="fade-in-up"></div>',
                title: 'Report Elements',
                ncyBreadcrumb: {
                    label: 'Report Elements'
                }
            }).state('app.report.view', {
                url: '/elements',
                templateUrl: "assets/views/report/report.html",
                resolve: loadSequence('jquery-sparkline', 'angularBootstrapNavTree', 'spin', 'ladda', 'angular-ladda', 'moment', 'reportCtrl'),
                title: 'report.LISTDesc',
                ncyBreadcrumb: {
                    label: 'Report View'
                }
            })
            .state('app.system', {
                url: '/system',
                template: '<div ui-view class="fade-in-up"></div>',
                title: 'System Elements',
                ncyBreadcrumb: {
                    label: 'System Elements'
                }
            }).state('app.system.navmanager', {
                url: '/navmanager',
                templateUrl: "assets/views/system/navmanager.html",
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'navmanagerCtrl'),
                title: 'Nav Manager',
                ncyBreadcrumb: {
                    label: 'User Manager'
                }
            }).state('app.system.systemmanager', {
                url: '/systemmanager',
                templateUrl: "assets/views/system/systemmanager.html",
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'systemmanagerCtrl'),
                title: 'Nav Manager',
                ncyBreadcrumb: {
                    label: 'User Manager'
                }
            }).state('app.system.user', {
                url: '/user',
                template: '<div ui-view class="fade-in-up"></div>',
                title: 'User Manager',
                ncyBreadcrumb: {
                    label: 'User Manager'
                }
            }).state('app.system.user.requester', {
                url: '/requester',
                templateUrl: "assets/views/system/user/requester.html",
                title: 'User List Manager',
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'requestermgrCtrl'),
                ncyBreadcrumb: {
                    label: 'User List Manager'
                }
            }).state('app.system.user.user', {
                url: '/users',
                templateUrl: "assets/views/system/user/users.html",
                title: 'User List Manager',
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'usermgrCtrl'),
                ncyBreadcrumb: {
                    label: 'User List Manager'
                }
            }).state('app.system.user.role', {
                url: '/roles',
                templateUrl: "assets/views/system/user/role.html",
                title: 'User List Manager',
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'angularBootstrapNavTree', 'ui.grid', 'rolemgrCtrl'),
                ncyBreadcrumb: {
                    label: 'User List Manager'
                }
            }).state('app.system.user.group', {
                url: '/group',
                templateUrl: "assets/views/system/user/group.html",
                title: 'User List Manager',
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'groupmgrCtrl'),
                ncyBreadcrumb: {
                    label: 'User List Manager'
                }
            }).state('app.system.user.roleauthority', {
                url: '/roleauthority',
                templateUrl: "assets/views/system/user/roleauthority.html",
                title: 'User List Manager',
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'roleauthoritymgrCtrl'),
                ncyBreadcrumb: {
                    label: 'User List Manager'
                }
            }).state('app.system.user.groupauthority', {
                url: '/groupauthority',
                templateUrl: "assets/views/system/user/groupauthority.html",
                title: 'User List Manager',
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'groupauthoritymgrCtrl'),
                ncyBreadcrumb: {
                    label: 'User List Manager'
                }
            }).state('app.system.user.groupuser', {
                url: '/groupuser',
                templateUrl: "assets/views/system/user/groupuser.html",
                title: 'User List Manager',
                resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'groupusermgrCtrl'),
                ncyBreadcrumb: {
                    label: 'User List Manager'
                }
            }).state('app.system.form', {
                url: '/forms/{formKey}/{service}/{model}',
                // url: '/forms/{model}/{service}/{fields}/{url}/{cancelUrl}/{extjson}',
                templateUrl: "assets/views/system/tpl/form.html",
                title: 'ui-form',
                resolve: loadSequence('jquery-sparkline', 'api-check', 'formly', 'angularFormly', 'angularFileUpload', 'multi.select.tree', 'customformCtrl', 'sysformCtrl'),
                ncyBreadcrumb: {
                    label: 'ui-form'
                }
            }).state('app.system.form_editor', {
                url: '/form_editor/{formKey}/{service}/{model}',
                templateUrl: "assets/views/system/tpl/detail.html",
                title: 'ui-form',
                resolve: loadSequence('jquery-sparkline', 'api-check', 'formly', 'angularFormly', 'angularFileUpload', 'multi.select.tree', 'customformCtrl', 'sysformCtrl'),
                ncyBreadcrumb: {
                    label: 'ui-form'
                }
            }).state('app.system.form_role', {
                url: '/form_role/{formKey}/{service}/{model}',
                templateUrl: "assets/views/system/tpl/form.html",
                title: 'ui-form',
                resolve: loadSequence('jquery-sparkline', 'api-check', 'formly', 'angularFormly', 'angularFileUpload', 'multi.select.tree', 'customformCtrl', 'sysformCtrl'),
                ncyBreadcrumb: {
                    label: 'ui-form'
                }
            }).state('app.system.knowledgebase', {
                url: '/knowledgebase',
                templateUrl: "assets/views/system/knowledge.html",
                resolve: loadSequence('jquery-nestable-plugin', 'ng-nestable', 'ui.select', 'monospaced.elastic', 'touchspin-plugin', 'angularBootstrapNavTree', 'ckeditor-plugin', 'ckeditor', 'angularFileUpload', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'knowledgebaseCtrl'),
                title: 'knowledge.VIEW',
                ncyBreadcrumb: {
                    label: 'knowledge list'
                }
            })


        .state('app.system.origanization', {
            url: '/user',
            template: '<div ui-view class="fade-in-up"></div>',
            title: 'User Manager',
            ncyBreadcrumb: {
                label: 'User Manager'
            }
        }).state('app.system.origanization.detail', {
            url: '/detail',
            templateUrl: "assets/views/system/user/detail.html",
            title: 'User List Manager',
            resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'detailmgrCtrl'),
            ncyBreadcrumb: {
                label: 'User List Manager'
            }
        }).state('app.system.origanization.dept', {
            url: '/dept',
            templateUrl: "assets/views/system/user/dept.html",
            title: 'User List Manager',
            resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'deptmgrCtrl'),
            ncyBreadcrumb: {
                label: 'User List Manager'
            }
        }).state('app.system.origanization.workercalendar', {
            url: '/workercalendar',
            templateUrl: "assets/views/system/user/workercalendar.html",
            title: 'User List Manager',
            resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'workercalendarmgrCtrl'),
            ncyBreadcrumb: {
                label: 'User List Manager'
            }
        }).state('app.system.origanization.pbmanager', {
            url: '/pbmanager',
            templateUrl: "assets/views/system/user/pbmanager.html",
            title: 'User List Manager',
            resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'pbmanagermgrCtrl'),
            ncyBreadcrumb: {
                label: 'User List Manager'
            }
        })

        .state('app.ui', {
            url: '/ui',
            template: '<div ui-view class="fade-in-up"></div>',
            title: 'UI Elements',
            ncyBreadcrumb: {
                label: 'UI Elements'
            }
        }).state('app.ui.elements', {
            url: '/elements',
            templateUrl: "assets/views/ui_elements.html",
            title: 'Elements',
            icon: 'ti-layout-media-left-alt',
            ncyBreadcrumb: {
                label: 'Elements'
            }
        }).state('app.ui.buttons', {
            url: '/buttons',
            templateUrl: "assets/views/ui_buttons.html",
            title: 'Buttons',
            resolve: loadSequence('spin', 'ladda', 'angular-ladda', 'laddaCtrl'),
            ncyBreadcrumb: {
                label: 'Buttons'
            }
        }).state('app.ui.links', {
            url: '/links',
            templateUrl: "assets/views/ui_links.html",
            title: 'Link Effects',
            ncyBreadcrumb: {
                label: 'Link Effects'
            }
        }).state('app.ui.icons', {
            url: '/icons',
            templateUrl: "assets/views/ui_icons.html",
            title: 'Font Awesome Icons',
            ncyBreadcrumb: {
                label: 'Font Awesome Icons'
            },
            resolve: loadSequence('iconsCtrl')
        }).state('app.ui.lineicons', {
            url: '/line-icons',
            templateUrl: "assets/views/ui_line_icons.html",
            title: 'Linear Icons',
            ncyBreadcrumb: {
                label: 'Linear Icons'
            },
            resolve: loadSequence('iconsCtrl')
        }).state('app.ui.modals', {
            url: '/modals',
            templateUrl: "assets/views/ui_modals.html",
            title: 'Modals',
            ncyBreadcrumb: {
                label: 'Modals'
            },
            resolve: loadSequence('asideCtrl')
        }).state('app.ui.toggle', {
            url: '/toggle',
            templateUrl: "assets/views/ui_toggle.html",
            title: 'Toggle',
            ncyBreadcrumb: {
                label: 'Toggle'
            }
        }).state('app.ui.tabs_accordions', {
            url: '/accordions',
            templateUrl: "assets/views/ui_tabs_accordions.html",
            title: "Tabs & Accordions",
            ncyBreadcrumb: {
                label: 'Tabs & Accordions'
            },
            resolve: loadSequence('vAccordionCtrl')
        }).state('app.ui.panels', {
            url: '/panels',
            templateUrl: "assets/views/ui_panels.html",
            title: 'Panels',
            ncyBreadcrumb: {
                label: 'Panels'
            }
        }).state('app.ui.notifications', {
            url: '/notifications',
            templateUrl: "assets/views/ui_notifications.html",
            title: 'Notifications',
            ncyBreadcrumb: {
                label: 'Notifications'
            },
            resolve: loadSequence('toasterCtrl', 'sweetAlertCtrl')
        }).state('app.ui.treeview', {
            url: '/treeview',
            templateUrl: "assets/views/ui_tree.html",
            title: 'TreeView',
            ncyBreadcrumb: {
                label: 'Treeview'
            },
            resolve: loadSequence('angularBootstrapNavTree', 'treeCtrl')
        }).state('app.ui.media', {
            url: '/media',
            templateUrl: "assets/views/ui_media.html",
            title: 'Media',
            ncyBreadcrumb: {
                label: 'Media'
            }
        }).state('app.ui.nestable', {
            url: '/nestable2',
            templateUrl: "assets/views/ui_nestable.html",
            title: 'Nestable List',
            ncyBreadcrumb: {
                label: 'Nestable List'
            },
            resolve: loadSequence('jquery-nestable-plugin', 'ng-nestable', 'nestableCtrl')
        }).state('app.ui.typography', {
            url: '/typography',
            templateUrl: "assets/views/ui_typography.html",
            title: 'Typography',
            ncyBreadcrumb: {
                label: 'Typography'
            }
        }).state('app.table', {
            url: '/table',
            template: '<div ui-view class="fade-in-up"></div>',
            title: 'Tables',
            ncyBreadcrumb: {
                label: 'Tables'
            }
        }).state('app.table.basic', {
            url: '/basic',
            templateUrl: "assets/views/table_basic.html",
            title: 'Basic Tables',
            ncyBreadcrumb: {
                label: 'Basic'
            }
        }).state('app.table.responsive', {
            url: '/responsive',
            templateUrl: "assets/views/table_responsive.html",
            title: 'Responsive Tables',
            ncyBreadcrumb: {
                label: 'Responsive'
            }
        }).state('app.table.data', {
            url: '/data',
            templateUrl: "assets/views/table_data.html",
            title: 'ngTable',
            ncyBreadcrumb: {
                label: 'ngTable'
            },
            resolve: loadSequence('ngTable', 'ngTableCtrl')
        }).state('app.table.export', {
            url: '/export',
            templateUrl: "assets/views/table_export.html",
            title: 'Table'
        }).state('app.form', {
            url: '/form',
            template: '<div ui-view class="fade-in-up"></div>',
            title: 'Forms',
            ncyBreadcrumb: {
                label: 'Forms'
            }
        }).state('app.form.elements', {
            url: '/elements',
            templateUrl: "assets/views/form_elements.html",
            title: 'Forms Elements',
            ncyBreadcrumb: {
                label: 'Elements'
            },
            resolve: loadSequence('ui.select', 'monospaced.elastic', 'ui.mask', 'touchspin-plugin', 'selectCtrl')
        }).state('app.form.xeditable', {
            url: '/xeditable',
            templateUrl: "assets/views/form_xeditable.html",
            title: 'Angular X-Editable',
            ncyBreadcrumb: {
                label: 'X-Editable'
            },
            resolve: loadSequence('xeditable', 'checklist-model', 'xeditableCtrl')
        }).state('app.form.texteditor', {
            url: '/editor',
            templateUrl: "assets/views/form_text_editor.html",
            title: 'Text Editor',
            ncyBreadcrumb: {
                label: 'Text Editor'
            },
            resolve: loadSequence('ckeditor-plugin', 'ckeditor', 'ckeditorCtrl')
        }).state('app.form.wizard', {
            url: '/wizard',
            templateUrl: "assets/views/form_wizard.html",
            title: 'Form Wizard',
            ncyBreadcrumb: {
                label: 'Wizard'
            },
            resolve: loadSequence('wizardCtrl')
        }).state('app.form.validation', {
            url: '/validation',
            templateUrl: "assets/views/form_validation.html",
            title: 'Form Validation',
            ncyBreadcrumb: {
                label: 'Validation'
            },
            resolve: loadSequence('validationCtrl')
        }).state('app.form.cropping', {
            url: '/image-cropping',
            templateUrl: "assets/views/form_image_cropping.html",
            title: 'Image Cropping',
            ncyBreadcrumb: {
                label: 'Image Cropping'
            },
            resolve: loadSequence('ngImgCrop', 'cropCtrl')
        }).state('app.form.upload', {
            url: '/file-upload',
            templateUrl: "assets/views/form_file_upload.html",
            title: 'Multiple File Upload',
            ncyBreadcrumb: {
                label: 'File Upload'
            },
            resolve: loadSequence('angularFileUpload', 'uploadCtrl')
        }).state('app.pages', {
            url: '/pages',
            template: '<div ui-view class="fade-in-up"></div>',
            title: 'Pages',
            ncyBreadcrumb: {
                label: 'Pages'
            }
        }).state('app.pages.user', {
            url: '/user',
            templateUrl: "assets/views/pages_user_profile.html",
            title: 'User Profile',
            ncyBreadcrumb: {
                label: 'User Profile'
            },
            resolve: loadSequence('flow', 'userCtrl')
        }).state('app.pages.invoice', {
            url: '/invoice',
            templateUrl: "assets/views/pages_invoice.html",
            title: 'Invoice',
            ncyBreadcrumb: {
                label: 'Invoice'
            }
        }).state('app.pages.timeline', {
            url: '/timeline',
            templateUrl: "assets/views/pages_timeline.html",
            title: 'Timeline',
            ncyBreadcrumb: {
                label: 'Timeline'
            },
            resolve: loadSequence('ngMap')
        }).state('app.pages.calendar', {
            url: '/calendar',
            templateUrl: "assets/views/pages_calendar.html",
            title: 'Calendar',
            ncyBreadcrumb: {
                label: 'Calendar'
            },
            resolve: loadSequence('moment', 'mwl.calendar', 'calendarCtrl')
        }).state('app.pages.messages', {
            url: '/messages',
            templateUrl: "assets/views/pages_messages.html",
            resolve: loadSequence('truncate', 'htmlToPlaintext', 'inboxCtrl')
        }).state('app.pages.messages.inbox', {
            url: '/inbox/:inboxID',
            templateUrl: "assets/views/pages_inbox.html",
            controller: 'ViewMessageCrtl'
        }).state('app.pages.blank', {
            url: '/blank',
            templateUrl: "assets/views/pages_blank_page.html",
            ncyBreadcrumb: {
                label: 'Starter Page'
            }
        }).state('app.utilities', {
            url: '/utilities',
            template: '<div ui-view class="fade-in-up"></div>',
            title: 'Utilities',
            ncyBreadcrumb: {
                label: 'Utilities'
            }
        }).state('app.utilities.search', {
            url: '/search',
            templateUrl: "assets/views/utility_search_result.html",
            title: 'Search Results',
            ncyBreadcrumb: {
                label: 'Search Results'
            }
        }).state('app.utilities.pricing', {
            url: '/pricing',
            templateUrl: "assets/views/utility_pricing_table.html",
            title: 'Pricing Table',
            ncyBreadcrumb: {
                label: 'Pricing Table'
            }
        }).state('app.maps', {
            url: "/maps",
            templateUrl: "assets/views/maps.html",
            resolve: loadSequence('ngMap', 'mapsCtrl'),
            title: "Maps",
            ncyBreadcrumb: {
                label: 'Maps'
            }
        }).state('app.charts', {
            url: "/charts",
            templateUrl: "assets/views/charts.html",
            resolve: loadSequence('chartjs', 'tc.chartjs', 'chartsCtrl'),
            title: "Charts",
            ncyBreadcrumb: {
                label: 'Charts'
            }
        }).state('app.documentation', {
            url: "/documentation",
            templateUrl: "assets/views/documentation.html",
            title: "Documentation",
            ncyBreadcrumb: {
                label: 'Documentation'
            }
        }).state('error', {
            url: '/error',
            template: '<div ui-view class="fade-in-up"></div>'
        }).state('error.404', {
            url: '/404',
            templateUrl: "assets/views/utility_404.html"
        }).state('error.500', {
            url: '/500',
            templateUrl: "assets/views/utility_500.html"
        })

        //customform
        .state('app.customform', {
                url: '/customform',
                templateUrl: 'assets/views/customform/index.html',
                resolve: loadSequence('jquery-sparkline', 'ckeditor-plugin', 'ckeditor', 'api-check', 'formly', 'angularFormly', 'angularFileUpload', 'multi.select.tree', 'customformCtrl'),
                title: 'Customform',
                ncyBreadcrumb: {
                    label: 'Customform'
                }
            })
            .state('app.detail', {
                url: '/detail/:formKey/:pdKey/:dataId/:taskId/:processInstanceId',
                templateUrl: "assets/views/customform/detail.html",
                resolve: loadSequence('jquery-sparkline', 'api-check', 'formly', 'angularFormly', 'angularFileUpload', 'multi.select.tree', 'customformCtrl', 'customformDetailCtrl'),
                title: 'form detail',
                icon: 'ti-list',
                ncyBreadcrumb: {
                    label: 'detail'
                }
            })

        // Login routes

        .state('login', {
                url: '/login',
                template: '<div ui-view class="fade-in-right-big smooth"></div>',
                abstract: true
            }).state('login.signin', {
                url: '/signin',
                templateUrl: "assets/views/login_login.html",
                resolve: loadSequence('sweet-alert', 'oitozero.ngSweetAlert', 'loginCtrl')
            }).state('login.forgot', {
                url: '/forgot',
                templateUrl: "assets/views/login_forgot.html"
            })
            /*.state('login.registration', {
            	    url: '/registration',
            	    templateUrl: "assets/views/login_registration.html"
            	})*/
            .state('login.lockscreen', {
                url: '/lock',
                templateUrl: "assets/views/login_lock_screen.html"
            }).state('app.easyform', {
                url: '/easyform',
                templateUrl: "assets/views/easyform/easyform.html",
                //'api-check','formly','angularFormly', 'nya-bs-select', 
                resolve: loadSequence('api-check', 'formly', 'angularFormly', 'nya-bs-select', 'easyformCtrl'),
                title: 'easy form',
                icon: 'ti-list',
                ncyBreadcrumb: {
                    label: 'easyform'
                }
            })
            // .state('login.changepassword', {
            //     url: '/changepassword',
            //     templateUrl: "assets/views/changepassword.html",
            //     resolve: loadSequence('jquery-sparkline', 'spin', 'ladda', 'angular-ladda', 'ui.grid', 'passwordCtrl'),
            //     title: 'changepassword',
            //     icon: 'ti-list',
            //     ncyBreadcrumb: {
            //         label: 'changepassword'
            //     }
            // });


        // Generates a resolve object previously configured in constant.JS_REQUIRES (config.constant.js)
        function loadSequence() {
            var _args = arguments;
            return {
                deps: ['$ocLazyLoad', '$q',
                    function($ocLL, $q) {
                        var promise = $q.when(1);
                        for (var i = 0, len = _args.length; i < len; i++) {
                            promise = promiseThen(_args[i]);
                        }
                        return promise;

                        function promiseThen(_arg) {
                            if (typeof _arg == 'function')
                                return promise.then(_arg);
                            else
                                return promise.then(function() {
                                    var nowLoad = requiredData(_arg);
                                    if (!nowLoad)
                                        return $.error('Route resolve: Bad resource name [' + _arg + ']');
                                    return $ocLL.load(nowLoad);
                                });
                        }

                        function requiredData(name) {
                            if (jsRequires.modules)
                                for (var m in jsRequires.modules)
                                    if (jsRequires.modules[m].name && jsRequires.modules[m].name === name)
                                        return jsRequires.modules[m];
                            return jsRequires.scripts && jsRequires.scripts[name];
                        }
                    }
                ]
            };
        }
    }
]);